import { Column, PrimaryGeneratedColumn, OneToMany, JoinColumn } from "typeorm";
import { EntityModel } from "@midwayjs/orm";
import { MaterialDonate } from "./MaterialDonate.entity";

@EntityModel("material", { schema: "heart_neighbor" })
export class Material {
  @PrimaryGeneratedColumn({ type: "int", name: "id", comment: "Primary Key" })
  id!: number;

  @Column("datetime", {
    name: "create_time",
    nullable: true,
    comment: "Create Time",
    default: () => "CURRENT_TIMESTAMP",
  })
  createTime!: Date | null;

  @Column("varchar", {
    name: "name",
    nullable: true,
    comment: "物资名称",
    length: 255,
  })
  name!: string | null; 

  @Column("int", { name: "price", nullable: true, comment: "物资价格" })
  price!: number | null;

  @Column("varchar", {
    name: "tag",
    nullable: true,
    comment: "物资标签",
    length: 255,
  })
  tag!: string | null;

  @Column("varchar", {
    name: 'img',
    nullable: true,
    comment: '物资图片',
    length: 255
  })
  img!: string | null

  @Column("tinyint", {
    name: "category",
    nullable: true,
    comment: "物资分类，1食品2医疗3文具",
    width: 1,
    default: () => "'1'",
  })
  category!: boolean | null;

  @Column("varchar", {
    name: "description",
    nullable: true,
    comment: "物资描述",
    length: 255,
  })
  description!: string | null;

  // 一对多关系：一个物资可以有多个物资捐赠需求
  @OneToMany(() => MaterialDonate, (materialDonate) => materialDonate.material, { createForeignKeyConstraints: false })
  @JoinColumn({ name: "id" })
  materialDonates!: MaterialDonate[];


}
